using System;
using System.IO;



namespace filesystem.paths
{
	public class SearchPath
	{
		public static FileSystemInfo FindClosest(string filename)
		{
			for (var node = new DirectoryInfo(".");
			     node != null; node = node.Parent) {
				FileSystemInfo check_file = new FileInfo(Path.Combine(node.FullName, filename));
				if (check_file.Exists)
					return check_file;
				else {
					check_file = new DirectoryInfo(check_file.FullName);
					if (check_file.Exists)
						return check_file;
				}
			}
			
			throw new FileNotFoundException("File was not found nearby", filename);
		}
	}
}

